﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using SYH.Config;

namespace SYH.Public.DAL
{
    public class Public_Messages
    {
        #region 得到站内信表的对象实体
        /// <summary>
        /// 得到站内信表的对象实体
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public Model.Public_Messages GetModel(string id)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("SELECT [Id],[Title],[Contents],[IsReply],[InfoId],[CreateTime] FROM [QHW_Shop].[dbo].[Public_WebMessage] where Id = @Id");
            SqlParameter parameter = new SqlParameter("@Id", SqlDbType.Int, 4);
            parameter.Value = id;
            SqlDataReader reader = Common.SqlHelper.ExecuteReader(WebConfig.SqlConnString, CommandType.Text, strSql.ToString(), parameter);
            Model.Public_Messages model = new Model.Public_Messages();
            if (reader.HasRows)
            {
                while (reader.Read())
                {
                    model.Id = reader.GetInt32(reader.GetOrdinal("Id"));
                    model.Title = reader.GetString(reader.GetOrdinal("Title"));
                    model.Contents = reader.GetString(reader.GetOrdinal("Contents"));
                    model.IsReply = reader.GetInt32(reader.GetOrdinal("IsReply"));
                    //model. = reader.GetInt32(reader.GetOrdinal("InfoId"));
                    model.CreateTime = reader.GetDateTime(reader.GetOrdinal("CreateTime"));
                }
                reader.Close();
                return model;
            }
            reader.Close();
            return null;
        }
        #endregion

        #region 站内信详细页使用，查找当前收到消息及回复消息
        public DataSet GetAllMsgCurrent(int infoId)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append(@"SELECT Public_WebMessage.Id, Public_WebMessage.Title, Public_WebMessage.Contents, Public_WebMessage.IsReply, Public_WebMessage.InfoId, Public_WebMessage.CreateTime, Public_WebMessageSenders.TypeId FROM Public_WebMessage INNER JOIN Public_WebMessageSenders ON Public_WebMessage.Id = Public_WebMessageSenders.MailID where InfoId =@infoID order by Id");
            SqlParameter parameter = new SqlParameter("@infoID", SqlDbType.Int, 4);
            parameter.Value = infoId;
            DataSet ds = Common.SqlHelper.ExecuteDataset(WebConfig.SqlConnString, CommandType.Text, strSql.ToString(), parameter);
            return ds;
        }
        #endregion
    }
}
